package com.github.sd4324530.fastweixin.api.extra;

import java.io.Serializable;

/**
 * token的cache对象
 */
public class Token implements Serializable{
    private static final long serialVersionUID = -5371773678345353692L;
    private Long updateTime;
    private String token;
    private String appid;
    private TokenType type;

    Token() {
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public String getToken() {
        return token;
    }

    String getAppid() {
        return appid;
    }

    TokenType getType() {
        return type;
    }

    void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    void setToken(String token) {
        this.token = token;
    }

    void setAppid(String appid) {
        this.appid = appid;
    }

    void setType(TokenType type) {
        this.type = type;
    }

    Token copy() {
        Token token = new Token();
        token.setUpdateTime(this.updateTime);
        token.setToken(this.token);
        return token;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Token token1 = (Token) o;

        if (updateTime != null ? !updateTime.equals(token1.updateTime) : token1.updateTime != null) return false;
        if (token != null ? !token.equals(token1.token) : token1.token != null) return false;
        if (appid != null ? !appid.equals(token1.appid) : token1.appid != null) return false;
        return type == token1.type;

    }

    @Override
    public int hashCode() {
        int result = updateTime != null ? updateTime.hashCode() : 0;
        result = 31 * result + (token != null ? token.hashCode() : 0);
        result = 31 * result + (appid != null ? appid.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Token{" +
            "updateTime=" + updateTime +
            ", token='" + token + '\'' +
            ", appid='" + appid + '\'' +
            ", type=" + type +
            '}';
    }
}
